package com.smart.campus.web.controller.school;

import java.util.Date;
import java.util.List;

import com.smart.campus.school.domain.vo.PsychologicalTestRecordVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.PsychologicalTestRecord;
import com.smart.campus.school.service.IPsychologicalTestRecordService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 心理测试记录Controller
 * 
 * @author Zhihe.Li
 * @date 2020-05-27
 */
@Controller
@RequestMapping("/school/psychologicaRecord")
public class PsychologicalTestRecordController extends BaseController
{
    private String prefix = "school/psychologicaRecord";

    @Autowired
    private IPsychologicalTestRecordService psychologicalTestRecordService;

    @RequiresPermissions("school:psychologicaRecord:view")
    @GetMapping()
    public String psychologicaRecord()
    {
        return prefix + "/psychologicaRecord";
    }

    /**
     * 查询心理测试记录列表
     */
    @RequiresPermissions("school:psychologicaRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PsychologicalTestRecordVo psychologicalTestRecord)
    {
        startPage();
        List<PsychologicalTestRecordVo> list = psychologicalTestRecordService.selectPsychologicalTestRecordList(psychologicalTestRecord);
        return getDataTable(list);
    }

    /**
     * 导出心理测试记录列表
     */
    @RequiresPermissions("school:psychologicaRecord:export")
    @Log(title = "心理测试记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PsychologicalTestRecordVo psychologicalTestRecord)
    {
        List<PsychologicalTestRecordVo> list = psychologicalTestRecordService.selectPsychologicalTestRecordList(psychologicalTestRecord);
        ExcelUtil<PsychologicalTestRecordVo> util = new ExcelUtil<PsychologicalTestRecordVo>(PsychologicalTestRecordVo.class);
        return util.exportExcel(list, "psychologicaRecord");
    }

    /**
     * 新增心理测试记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存心理测试记录
     */
    @RequiresPermissions("school:psychologicaRecord:add")
    @Log(title = "心理测试记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PsychologicalTestRecord psychologicalTestRecord)
    {
        psychologicalTestRecord.setTestTime(new Date());
        psychologicalTestRecord.setStatus(1);
        return toAjax(psychologicalTestRecordService.insertPsychologicalTestRecord(psychologicalTestRecord));
    }

    /**
     * 修改心理测试记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PsychologicalTestRecord psychologicalTestRecord = psychologicalTestRecordService.selectPsychologicalTestRecordById(id);
        mmap.put("psychologicalTestRecord", psychologicalTestRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存心理测试记录
     */
    @RequiresPermissions("school:psychologicaRecord:edit")
    @Log(title = "心理测试记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PsychologicalTestRecord psychologicalTestRecord)
    {
        return toAjax(psychologicalTestRecordService.updatePsychologicalTestRecord(psychologicalTestRecord));
    }

    /**
     * 删除心理测试记录
     */
    @RequiresPermissions("school:psychologicaRecord:remove")
    @Log(title = "心理测试记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(psychologicalTestRecordService.deletePsychologicalTestRecordByIds(ids));
    }
}
